using System;
using UnityEngine;

public abstract class BMThemeBase : MonoBehaviour
{
	public string ThemeName { get; private set; }

	public abstract ThemeItem[] ThemeItems { get; set; }

	public virtual Color Color
	{
		get
		{
			return default(Color);
		}
		set
		{
		}
	}

	protected virtual void Awake()
	{
		this.orgPos = base.transform.localPosition;
	}

	private void OnEnable()
	{
		BMTheme.Instance.Register(this);
	}

	private void OnDestroy()
	{
		BMTheme.Instance.Unregister(this);
	}

	public virtual bool Change(string themeName)
	{
		this.ThemeName = themeName;
		ThemeItem themeItem = this.GetThemeItem(themeName);
		if (themeItem == null)
		{
			return false;
		}
		base.gameObject.SetActive(themeItem.enabled);
		if (!base.gameObject.activeSelf)
		{
			return false;
		}
		this.Color = themeItem.color;
		if (this.useOffset)
		{
			Vector3 localPosition = this.orgPos;
			localPosition.x += themeItem.offset.x;
			localPosition.y += themeItem.offset.y;
			base.transform.localPosition = localPosition;
		}
		return true;
	}

	public virtual void ResetTheme()
	{
		if (this.ThemeName == null)
		{
			UnityEngine.Debug.Log("ThemeName is null.");
			return;
		}
		this.Change(this.ThemeName);
	}

	protected ThemeItem GetThemeItem(string themeName)
	{
		if (this.ThemeItems == null)
		{
			return null;
		}
		foreach (ThemeItem themeItem in this.ThemeItems)
		{
			if (themeItem != null)
			{
				if (themeItem.themeName == themeName)
				{
					return themeItem;
				}
			}
		}
		return null;
	}

	public bool useOffset;

	protected Vector3 orgPos;
}
